package math.geom2d;

import math.base.Point2d;
import math.base.Vector2d;
import math.geomUtils.CurveType;

/**
 * @author Saga
 *
 */
public class TrimmedCurve2d extends BoundedCurve2d {
    public TrimmedCurve2d(final Curve2d _baseCurve, final double _firstParam,
            final double _lastParam) {
        this.baseCurve = _baseCurve;

        //todo,check
        this.firstParam = _firstParam;
        this.lastParam = _lastParam;

        this.firstPt = this.baseCurve.calcValue(_firstParam);
        this.lastPt = this.baseCurve.calcValue(_lastParam);
    }

    @Override
    public CurveType getCurveType() {
        return CurveType.TRIMMED_CURVE;
    }

    @Override
    public void reverse() {
        this.baseCurve.reverse();
        if (this.baseCurve.isPeriodic()) {
            final double period = this.baseCurve.getPeriod();
            final double temp = period - this.firstParam;
            this.lastParam = temp;

        } else {

        }
    }

    public Curve2d reversed() {
        return null;
    }

    @Override
    public final boolean isPeriodic() {
        return this.baseCurve.isPeriodic();
    }

    @Override
    public final double getPeriod() {
        return this.baseCurve.getPeriod();
    }

    @Override
    public final void setFirstParameter(final double _param) {
        this.firstParam = _param;
        this.firstPt = this.baseCurve.calcValue(_param);
    }

    @Override
    public final void setLastParameter(final double _param) {
        this.lastParam = _param;
        this.lastPt = this.baseCurve.calcValue(_param);
    }

    @Override
    public final Point2d calcValue(final double _param) {
        return this.baseCurve.calcValue(_param);
    }

    @Override
    public final Vector2d calcDerivative(final double _param) {
        return this.baseCurve.calcDerivative(_param);
    }

    @Override
    public final Vector2d calcDerivativeN(final double _param, final int _order) {
        return this.calcDerivativeN(_param, _order);
    }

    @Override
    public final void calcValueAndDerivative1(final double _param, final Point2d _pt,
            final Vector2d _der1) {
        this.baseCurve.calcValueAndDerivative1(_param, _pt, _der1);
    }

    @Override
    public final void calcValueAndDerivative2(final double _param, final Point2d _pt,
            final Vector2d _der1, final Vector2d _der2) {
        this.baseCurve.calcValueAndDerivative2(_param, _pt, _der1, _der2);
    }

    @Override
    public final void calcValueAndDerivative3(final double _param, final Point2d _pt,
            final Vector2d _der1, final Vector2d _der2, final Vector2d _der3) {
        this.baseCurve.calcValueAndDerivative3(_param, _pt, _der1, _der2, _der3);
    }

    protected final Curve2d baseCurve;
}
